package cn.anc.aonicardv.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.Scroller;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

public class AutoScrollRecycleView extends RecyclerView {

    private Scroller mScroller;

    public AutoScrollRecycleView(Context context) {
        super(context);
    }

    public AutoScrollRecycleView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Scroller getScroller() {
        return mScroller;
    }

    public void setScroller(Scroller scroller) {
        this.mScroller = scroller;
    }

    int lastX;

    @Override
    public void computeScroll() {
        if (mScroller != null && mScroller.computeScrollOffset()) {
            int currX = mScroller.getCurrX();
            int x = currX - lastX;
            lastX = currX;
            scrollBy(x, mScroller.getCurrY());
        }
    }
}
